<%= csrf_meta_tags %>

<header class="flex items-center mb-6">
  <h1 class="crayons-title">Pages</h1>
  <div class="ml-auto flex gap-2">
    <%= link_to "Page Templates", admin_page_templates_path, class: "crayons-btn crayons-btn--s crayons-btn--secondary" %>
    <%= link_to "New page", new_admin_page_path, class: "crayons-btn crayons-btn--s" %>
  </div>
</header>

<% if @page_templates.any? %>
  <div class="crayons-notice crayons-notice--info mb-6" aria-live="polite">
    <strong>Tip:</strong> You have <%= @page_templates.count %> page template(s) available. 
    <%= link_to "Create a page from a template", admin_page_templates_path, class: "crayons-link" %> 
    to quickly spin up new pages with pre-defined layouts.
  </div>
<% end %>

<div class="crayons-card p-6 pages__table">
  <% @pages.each do |page| %>
    <div class="flex py-2 items-center" data-testid="page">
      <div class="flex items-center gap-2">
        <% if page.landing_page? %>
          <%= crayons_icon_tag(:lock, title: "Current locked screen") %>
        <% end %>
        <%= link_to page.title, page.path %>
        <% if page.page_template.present? %>
          <span class="crayons-tag crayons-tag--monochrome fs-xs" title="Created from template">
            <%= page.page_template.name %>
          </span>
        <% end %>
      </div>
      <div class="ml-auto flex gap-2">
        <%= link_to "Edit", edit_admin_page_path(page.id), class: "crayons-btn crayons-btn--s crayons-btn--secondary" %>
        <%= link_to "Fork", new_admin_page_path(page: page.id), class: "crayons-btn crayons-btn--s crayons-btn--secondary" %>
      </div>
    </div>
  <% end %>
</div>

<div class="mt-8 pages__override_defaults">
  <div class="my-6">
    <% if !@code_of_conduct || !@privacy || !@terms %>
      <h2 class="crayons-subtitle-1 mb-4">Override defaults</h2>
      <div class="crayons-notice mb-4 crayons-notice--warning" aria-live="polite">
        <strong>Note: Proceed with caution. When you edit any of the following pages, it will diverge from the original Forem version and you will no longer receive updates. You will see your updated version in the section above.</strong>
      </div>
      <div class="crayons-card p-6">
        <% if !@code_of_conduct %>
          <div class="flex py-2 items-center">
              <%= link_to "Code of Conduct", code_of_conduct_path %>
              <%= link_to "Override", new_admin_page_path(slug: "code-of-conduct"), class: "ml-auto crayons-btn crayons-btn--s crayons-btn--danger" %>
          </div>
        <% end %>
        <% if !@privacy %>
          <div class="flex py-2 items-center">
              <%= link_to "Privacy Policy", privacy_path %>
              <%= link_to "Override", new_admin_page_path(slug: "privacy"), class: "ml-auto crayons-btn crayons-btn--s crayons-btn--danger" %>
          </div>
        <% end %>
        <% if !@terms %>
          <div class="flex py-2 items-center">
              <%= link_to "Terms of Use", terms_path %>
              <%= link_to "Override", new_admin_page_path(slug: "terms"), class: "ml-auto crayons-btn crayons-btn--s crayons-btn--danger" %>
          </div>
        <% end %>
      </div>
    <% else %>
      <div class="crayons-notice crayons-notice--info" aria-live="polite">
        <strong>Note: You have overridden the code of conduct, privacy policy and terms of use. You will no longer receive updates on these pages from the Forem team.</strong>
      </div>
    <% end %>
  </div>
</div>
